// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/broadcast/api/BroadcastTerminalApi'

import ComClass from '@api/ComQuery'
import ListClass from '@api/broadcast/model/QueryTerminalListReq'
import EditClass from '@api/broadcast/model/BroadcastTerminalSetVolReq'

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 列表 —————————————————————————————— //

  validParam(param) {
    return !CORE.isEmpty(param.statusList)
  },
  async getList(param, TIP = '查询列表') {
    const DTO = CORE.grpcDTO(ListClass, param, COM)
    const resp = await CORE.grpc(TIP, CLIENT, 'queryTerminalList', DTO)
    return [resp.comQuery.totalCount, resp.list || [], resp.map || {}]
  },
  transList(arr) {
    arr.forEach((item) => {
      item.detailId = item.id
    })
    return arr
  },

  // —————————————————————————————— 改 —————————————————————————————— //

  transEdit({ id, volume }, { state: { param: { idList } } }) {
    return { idList: id ? [id] : idList, volume }
  },
  async edit({ idList, volume }, TIP = '修改') {
    const DTO = CORE.grpcDTO(EditClass, { deviceId: idList, vol: volume })
    await CORE.grpc(TIP, CLIENT, 'broadcastTerminalSetVol', DTO)
    return CORE.grpcOK(TIP)
  },
}
